function foo() {
  return  new Promise((resolve,reject)=>{
    setTimeout(() => {
      console.log(1);
      resolve()
    }, 1000)
  })
}



function bar() {
  setTimeout(() => {  
    console.log(2);
  }, 500)
}


function baz() {
  setTimeout(() => {
    console.log(3);
  }, 100)
}


//  Promise 三种状态 ，pending，resolved，rejected
foo()
  .then(() => {   //then 也会返回一个promise对象
    bar()
  }).then(() => {  //promise.resolve().then()
    baz()
  })
  .then(() => { 
    console.log(4);
  })
